package com.iwdnb.gkgz.common.quota;

import java.util.List;

import com.iwdnb.gkgz.common.model.dto.StockDayData;
import com.iwdnb.gkgz.common.utils.BigDecimalUtils;
import org.apache.commons.collections4.CollectionUtils;

/**
 * 计算分时均价线
 */
public class FenshiAverage {

    public static void calculateFenshiAverage(List<StockDayData> stockDayDataList) {
        if (CollectionUtils.isEmpty(stockDayDataList) || stockDayDataList.size() <= 1) {
            return;
        }
        double price = 0d;
        int tradeNum = 0;
        for (int i = 0; i < stockDayDataList.size(); i++) {
            StockDayData stockDayData = stockDayDataList.get(i);
            price += stockDayData.getClosePrice().doubleValue() * stockDayData.getTradeNum();
            tradeNum += stockDayData.getTradeNum();
            if (tradeNum == 0) {
                tradeNum = 1;
            }
            stockDayData.setAvgPrice(BigDecimalUtils.of(price / (tradeNum)));
        }
    }

}
